﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.WindowsAPICodePack.Taskbar;
using Microsoft.WindowsAPICodePack.Dialogs;

namespace ImageConvert
{
    public class Windows
    {
        private TaskbarManager _taskbar;
        private bool _supported;

        public Windows()
        {
            _supported = TaskbarManager.IsPlatformSupported;
            if (_supported)
            {
                _taskbar = TaskbarManager.Instance;
            }
        }

        public void SetTaskbarProgessState(TaskbarProgressBarState State)
        {
            if (!_supported) return;
            _taskbar.SetProgressState(State);
        }

        public void SetTaskbarProgressValue(int current, int max)
        {
            if (!_supported) return;
            _taskbar.SetProgressValue(current, max);
        }

        public string OpenDirectory(string InitialPath)
        {
            CommonOpenFileDialog cfd = new CommonOpenFileDialog();
            cfd.EnsureReadOnly = true;
            cfd.IsFolderPicker = true;
            cfd.AllowNonFileSystemItems = true;
            if (!string.IsNullOrEmpty(InitialPath)) cfd.InitialDirectory = InitialPath;
            if (cfd.ShowDialog() == CommonFileDialogResult.Ok) return cfd.FileName;
            else return null;
        }

        public string[] OpenFiles(string InitialPath)
        {

            if (Environment.OSVersion.Version.Major <= 6 && Environment.OSVersion.Version.Minor < 1)
            {
                System.Windows.Forms.OpenFileDialog ofd = new System.Windows.Forms.OpenFileDialog();
                ofd.Multiselect = true;
                ofd.CheckFileExists = true;
                if (!string.IsNullOrEmpty(InitialPath)) ofd.InitialDirectory = InitialPath;
                if (ofd.ShowDialog() == System.Windows.Forms.DialogResult.OK) return ofd.FileNames;
                else return null;
            }
            else
            {
                CommonOpenFileDialog cfd = new CommonOpenFileDialog();
                cfd.EnsureReadOnly = false;
                cfd.AllowNonFileSystemItems = true;
                cfd.Multiselect = true;
                if (!string.IsNullOrEmpty(InitialPath)) cfd.InitialDirectory = InitialPath;
                if (cfd.ShowDialog() == CommonFileDialogResult.Ok) return cfd.FileNames.ToArray();
                else return null;
            }
        }
    }
}